var express = require("express");
var router = express.Router();
var { AdminModel } = require("../db/db");
var { userModel } = require("../db/user_model");

// 获取所有医生
router.get("/doctor", async (req, res) => {
    let data = await AdminModel.find()
    res.send({
        data,
        mes:"查找成功"
    })
})

// 获取用户列表
router.get("/user_list", async (req, res) => {
  console.log(req.query);
  let list = await userModel
    .find()
    .exec();
  total = list.length;
  res.send({
    code: 200,
    msg: "展示成功",
    data: list,
    total: total,
  });
});
// 添加用户
router.post("/add_user", async (req, res) => {
  let body = req.body;
  await userModel.create(body);
  res.send({
    code: 200,
    msg: "添加成功",
  });
});
// 修改用户
router.put("/edit_user/:id", async function (req, res) {
  let body = req.body;
  await userModel.updateOne({ _id: req.params.id }, { $set: body });
  res.send({
    code: 200,
    msg: "修改成功",
  });
});

module.exports = router;